<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>管理员登录-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
    <link type="text/css"  rel="stylesheet" href="../static/css/font.css">
	<link type="text/css" rel="stylesheet" href="../static/css/weadmin.css">
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../lib/jquery-3.2.1.min.js" charset="utf-8"></script>

</head>
<body class="login-bg">
    
    <div class="login">
        <div class="message">Bug统计考量脚本</div>
        <div id="darkbannerwrap"></div>
        
        <form method="post" class="layui-form">
            <input name="username" placeholder="用户名"  type="text" lay-verify="username" class="layui-input" >
            <hr class="hr15">
            <input name="password" lay-verify="password" placeholder="密码"  type="password" class="layui-input" >
            <hr class="hr15">
            <input class="loginin" value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
            <hr class="hr20" >
            <div>
                 <a href="/registerView" target="_blank">无账号，去注册</a>
            </div>
        </form>
    </div>

<!-- 定义表单相关校验 -->
<script type="text/javascript">
    //<!--定义layer-->
    layui.extend({
				admin: '{/}./static/js/admin'
			});
    layui.use('form', function () {
        var form = layui.form;

          //自定义验证规则 verify 针对layverify
          form.verify({
            username: function(value){
              if(value.length < 6){
                return '用户名至少得6个字符啊';
              }
              if(value.length > 12){
                return '用户名不能超过12个字符啊';
              }
            }
            ,password: [
              /^[\S]{6,12}$/
              ,'密码必须6到12位，且不能出现空格'
            ]

          });

          //监听提交
              form.on('submit(login)', function(data){

               //打印表单内容
                dataFiled = data.field;
                console.log("form-username == " + dataFiled.username);
                console.log("form-password == " + dataFiled.password);

                //请求后台数据
                $.ajax({
                    type: "post", //请求方法
                    url: "/login", //请求地址
                    data: {"username":dataFiled.username, "password":dataFiled.password},
                    //datatype: "json", //限制返回类型
                    //async:false,
                    success:function(datas){

                        //截取字符串前几位，如果是网页不做处理<!doctype html>
                        //subFrontDatas = datas.substring(0, 9); //包括前不包括后
                        //console.log("前15位==" + subFrontDatas);

                        console.log("返回类型" + typeof (datas));
                        console.log("发送登录请求成功，返回内容如下：");
                        datasJson = $.parseJSON(datas)
                        console.log("返回结果" + datas);
                        console.log(datasJson.code);
                        returnCode = datasJson.code
                        returnMsg = datasJson.msg
                        console.log("msg--type==" + typeof (returnMsg))
                        returnCount = datasJson.count
                        returnData = datasJson.data
                        if (returnCode == 500) { //== 字符串
                            console.log("登录失败,用户名或者密码错误");
                            layer.msg("登录失败,用户名或者密码错误")

                        }
                        if (returnCode == 200) {
                            console.log("登陆成功，跳转到主界面");
                            //成功的话，不在前台跳转，在后台跳转
                            location.href='/indexView';
                            //return true
                        `   `
                          }



                    },
                    error:function(){
                        console.log("前台点击登录，发送请求失败");
                    }
                });

                //让界面不跳转
                return false;
              });

    });

</script>
</body>
</html>